import threading

# local()是线程内的全局变量，与其他线程内的变量不会冲突

local_data = threading.local()
local_data.name = 'tolle'


def sample():
    print(threading.current_thread().name, local_data.__dict__)
    local_data.name = threading.current_thread().name
    print(threading.current_thread().getName(), local_data.__dict__)


for i in range(2):
    t = threading.Thread(target=sample)
    t.start()
    t.join()
